package com.daisuxia.web.dao;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Repository;

import com.daisuxia.web.pojo.User;

@Repository
public class UserDao extends BaseDao implements IUserDao {

	/**
	 * 查询用户是否存在
	 * @param map
	 * @return
	 */
	public User searchUserByCheckTel(HashMap<String, Object> map){
		return this.getSqlSessionTemplate().selectOne("searchUserByCheckTel", map);
	}
	
	/**
	 * 根据ID查询用户
	 * @param id
	 * @return
	 */
	public User searchByUserid(int id){
		return this.getSqlSessionTemplate().selectOne("selectByUserId", id);
	}

	/**
	 * 催收根据ID查询用户
	 * @param id
	 * @return
	 */
	public User selectCollectionByUserId(int id){
		return this.getSqlSessionTemplate().selectOne("selectCollectionByUserId", id);
	}

	/**
	 * 根据用户ID查询验证码是否存在
	 * @param map
	 * @return
	 */
	public User searchByInviteUserid(Map<String, String> map){
		return this.getSqlSessionTemplate().selectOne("selectByUserIds", map);
	}
	
	/**
	 * 根据用户ID,手机号,证件号查询用户是否存在
	 * @param map
	 * @return
	 */
	public User searchByUphoneAndUid(Map<String, Object> map){
		return this.getSqlSessionTemplate().selectOne("selectByUPhoneAndUid", map);
	}
	/**
	 * 用户注册
	 * @param user
	 */
	public void saveUser(User user){
		this.getSqlSessionTemplate().insert("saveUser", user);
	}

	/**
	 * 用户登录
	 * @param map
	 * @return
	 */
	public User searchUserByLogin(HashMap<String, Object> map){
		return this.getSqlSessionTemplate().selectOne("searchUserByLogin", map);
	}
	
	/***
	 * 修改用户信息
	 */
	public int updateByPrimaryKeyUser(User user){
		return this.getSqlSessionTemplate().update("updateUser", user);
	}
	@Override
	public int deleteByPrimaryKeyUser(HashMap<String, Integer> map) {
		return this.getSqlSessionTemplate().delete("deleteUser",  map);
	}
	@Override
	public int updateAmountAvailableByUserId(User user) {
		return this.getSqlSessionTemplate().update("updateAmountAvailableByUserId", user);
	}

	@Override
	public User searchByUserIDCard(String idCard) {
		HashMap<String, String> map=new HashMap<String, String>();
		map.put("idCard", idCard);
		return this.getSqlSessionTemplate().selectOne("selectByUserIdCard", map);
	}
	@Override
	public int updateIndexInfoJxl(Integer userId){
		return this.getSqlSessionTemplate().update("updateResetIndexInfoJxl",userId);
	}
	@Override
	public int updateUserJxl(Integer userId){
		return this.getSqlSessionTemplate().update("updateResetUserJxl",userId);
	}
	@Override
	public int findJxlStatus(Integer userId){
		return this.getSqlSessionTemplate().selectOne("findResetJxlStatus",userId);
	}
	
	@Override
	public HashMap<String, Object> selectPushId(HashMap<String, Object> map) {
		return this.getSqlSessionTemplate().selectOne("selectPushIdByInviteUserid",map);
	}

	
}
